
/*
 * activiti新增外置表单选择页面
 */
var formOutCtrlLujingyuan = [ '$scope', '$modal','$http', function($scope, $modal,$http) {

    // Config for the modal window
    console.info("进入formOutCtrlLujingyuan");
    var opts = {
        template:  'editor-app/configuration/properties/formout-lujingyuan.html?version=' + Date.now(),
        scope: $scope
    };
    // Open the dialog
    $modal(opts);
}];

var formOutPopupCtrlLujingyuan= [ '$scope','$http', function($scope,$http) {
	// Put json representing form properties on scope
	console.info("$scope.property");
	console.info($scope.property);
	if ($scope.property.value !== undefined && $scope.property.value !== null) {
		// Note that we clone the json object rather then setting it directly,
		// this to cope with the fact that the user can click the cancel button and no changes should have happended
		$scope.value = angular.copy($scope.property.value);
		//$scope.aform = $scope.property.value.aform;
		$scope.aform = {formId:$scope.property.value,formName:$scope.property.formName}

	}else{
		$scope.aform = {};
	}

	/*$scope.save = function() {
		$scope.property.value=$scope.value+"1";
		$scope.updatePropertyInModel($scope.property);
		$scope.close();
	};*/

	//参数初始化
	$scope.gridData = [];//表格数据
	$scope.gridDataName = 'gridData';
	$scope.selectTitle = '选择代理人';
	$scope.columnData = [
		{
			field : 'id',
			type:'number',
			displayName : '表单Id',
			minWidth: 100,
			width : '50%'
		},
		{
			field : 'name',
			displayName : '表单名称',
			minWidth: 100,
			width : '50%'
		}];
	$scope.columnDataName = 'columnData';
	$scope.selectType = 0;//0-代理人，1-候选人，2-候选组
	$scope.totalServerItems = 0;//表格总条数
	//分页初始化
	$scope.pagingOptions = {
		pageSizes: [10, 20, 30],//page 行数可选值
		pageSize: 10, //每页行数
		currentPage: 1, //当前显示页数
	};
	//表格属性配置
	$scope.gridOptions = {
		data: $scope.gridDataName,
		multiSelect: false,//不可多选
		enablePaging: true,
		pagingOptions: $scope.pagingOptions,
		totalServerItems: 'totalServerItems',
		i18n:'zh-cn',
		showFooter: true,
		showSelectionCheckbox: false,
		columnDefs : $scope.columnDataName,
		beforeSelectionChange: function (event) {
			var data = event.entity.id;
			event.entity.checked = !event.selected;
			$scope.aform.formId = data+"";
			$scope.aform.formName = event.entity.name;
			return true;
		}
	};

	$scope.initForm= function(pageNum, pageSize){
		$http({
			method: 'POST',
			url: '/act/getFormList',
			params:{
				'pageNum': pageNum,
				'pageSize': pageSize
			},
		}).then(function successCallback(response) {
			$scope.gridData = response.data.rows;
			$scope.totalServerItems = response.data.total;
		}, function errorCallback(response) {
			// 请求失败执行代码
			$scope.gridData = [];
			$scope.totalServerItems = 0;
		});
	}
	$scope.initForm(1,10);

	// Close button handler
	$scope.close = function() {
		$scope.property.noValue=false;
		$scope.property.mode = 'read';
		$scope.$hide();
	};
	$scope.save = function() {
		$scope.property.value = "";
		$scope.property.value = $scope.aform.formId;
		$scope.property.formName = $scope.aform.formName;
		console.info($scope.property);
		$scope.updatePropertyInModel($scope.property);
		$scope.close();
	};
	$scope.clearForm = function () {
		$scope.aform.formId ='';
		$scope.aform.formName ='';
	};
}];
